package com.ruoyi.livesass.api.service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.ruoyi.livesass.api.domain.LbsZbll;
import com.ruoyi.livesass.api.mapper.LbsZbllMapper;
import com.ruoyi.livesass.api.pojo.query.LbsZbllQuery;

/**
 * 直播流量表Service业务层处理
 *
 *
 * @author ydb
 */
@Service
public class LbsZbllService {
    @Autowired
    private LbsZbllMapper lbsZbllMapper;

    /**
     * 查询直播流量表
     *
     * @param id 直播流量表主键
     * @return 直播流量表
     */
    public LbsZbll selectById(Long id) {
        return lbsZbllMapper.selectById(id);
    }

    /**
     * 查询直播流量表列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return 直播流量表
     */
    public List<LbsZbll> selectList(LbsZbllQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<LbsZbll> qw = new QueryWrapper<>();
        qw.eq("del_flag",0);
        String subname = query.getSubname();
        if (!StringUtils.isEmpty(subname)) {
            qw.eq("subname", subname);
        }
        String sszbjid = query.getSszbjid();
        if (!StringUtils.isEmpty(sszbjid)) {
            qw.eq("sszbjid", sszbjid);
        }
        
        String beginGsrq = query.getBeginGsrq();
        if (!StringUtils.isEmpty(beginGsrq)) {
            qw.ge("gsrq", beginGsrq);
        }
        
        String endGsrq = query.getEndGsrq();
        if (!StringUtils.isEmpty(endGsrq) ) {
            qw.le("gsrq", endGsrq);
        }
        
        Integer gkrs = query.getGkrs();
        if (gkrs != null) {
            qw.eq("gkrs", gkrs);
        }
        BigDecimal zbll = query.getZbll();
        if (zbll != null) {
            qw.eq("zbll", zbll);
        }
        BigDecimal zbllfy = query.getZbllfy();
        if (zbllfy != null) {
            qw.eq("zbllfy", zbllfy);
        }
        Long deptZbjId = query.getDeptZbjId();
        if (deptZbjId != null) {
            qw.eq("dept_zbj_id", deptZbjId);
        }
        
        qw.orderByDesc("gsrq");
        
        return lbsZbllMapper.selectList(qw);
    }

    /**
     * 新增直播流量表
     *
     * @param lbsZbll 直播流量表
     * @return 结果
     */
    public int insert(LbsZbll lbsZbll) {
        lbsZbll.setDelFlag("0");
        lbsZbll.setCreateTime(LocalDateTime.now());
        return lbsZbllMapper.insert(lbsZbll);
    }

    /**
     * 修改直播流量表
     *
     * @param lbsZbll 直播流量表
     * @return 结果
     */
    public int update(LbsZbll lbsZbll) {
        return lbsZbllMapper.updateById(lbsZbll);
    }

    /**
     * 批量删除直播流量表
     *
     * @param ids 需要删除的直播流量表主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return lbsZbllMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除直播流量表信息
     *
     * @param id 直播流量表主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return lbsZbllMapper.updateDelFlagByIds(ids);
    }
}
